﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using ThoiTrang.Business;
using ThoiTrang.Entities;

public partial class Admin_adm_seo_content : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        btnUpdate.ServerClick += new EventHandler(btnUpdate_ServerClick);
        if (!IsPostBack)
        {
            LoadData();
        }
    }

    void btnUpdate_ServerClick(object sender, EventArgs e)
    {
        try
        {
            a_SEO_Content seo = a_SEO_ContentService.Geta_SEO_ContentByCatSub(int.Parse(Request["scid"]));
            seo.MetaKeywords = MetaKeywords.Value;
            seo.MainKeyword = MainKeyword.Value;
            seo.MetaDesc = MetaDesc.Value;
            seo.AdjWords = int.Parse(AdjWords.Value);
            seo.DivHeight = int.Parse(DivHeight.Value);
            seo.Title = Title.Value;
            seo.H1 = H1.Value;
            seo.H2 = H2.Value;
            seo.FirstSentencePart = FirstSentencePart.Value;
            seo.Paragraph = Paragraph.Value;

            seo.ImgAlt1 = ImgAlt1.Value;
            seo.ImgAlt2 = ImgAlt2.Value;
            seo.ImgAlt3 = ImgAlt3.Value;
            seo.ImgAlt4 = ImgAlt4.Value;
            seo.ImgAlt5 = ImgAlt5.Value;
            seo.ImgAlt6 = ImgAlt6.Value;
            seo.ImgAlt7 = ImgAlt7.Value;
            seo.ImgAlt8 = ImgAlt8.Value;
            seo.ImgAlt9 = ImgAlt9.Value;

            seo.Comment1 = Comment1.Value;
            seo.Comment2 = Comment2.Value;
            seo.Comment3 = Comment3.Value;
            seo.Comment4 = Comment4.Value;

            a_SEO_ContentService.Updatea_SEO_Content(seo);

            msg.Visible = true;
            LoadData();
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }
    protected void LoadData()
    {
        try
        {
            a_SEO_Content seo = a_SEO_ContentService.Geta_SEO_ContentByCatSub(int.Parse(Request["scid"]));
            if (seo == null)
            {
                seo = new a_SEO_Content();
                a_CatSub CatSub = a_CatSubService.Geta_CatSub(int.Parse(Request["scid"]));
                seo.PageType = 2;
                seo.CatMainID = CatSub.MainCatID;
                seo.CatSubID = CatSub.SubCatID;
                a_SEO_ContentService.Createa_SEO_Content(seo);
            }
            MetaKeywords.Value = seo.MetaKeywords;
            MainKeyword.Value = seo.MainKeyword;
            MetaDesc.Value = seo.MetaDesc;
            AdjWords.Value = seo.AdjWords.ToString();
            DivHeight.Value = seo.DivHeight.ToString();
            Title.Value = seo.Title;
            H1.Value = seo.H1;
            H2.Value = seo.H2;
            FirstSentencePart.Value = seo.FirstSentencePart;
            Paragraph.Value = seo.Paragraph;

            ImgAlt1.Value = seo.ImgAlt1;
            ImgAlt2.Value = seo.ImgAlt2;
            ImgAlt3.Value = seo.ImgAlt3;
            ImgAlt4.Value = seo.ImgAlt4;
            ImgAlt5.Value = seo.ImgAlt5;
            ImgAlt6.Value = seo.ImgAlt6;
            ImgAlt7.Value = seo.ImgAlt7;
            ImgAlt8.Value = seo.ImgAlt8;
            ImgAlt9.Value = seo.ImgAlt9;
            
            Comment1.Value = seo.Comment1;
            Comment2.Value = seo.Comment2;
            Comment3.Value = seo.Comment3;
            Comment4.Value = seo.Comment4;
            
        }
        catch (Exception ex)
        {
            Response.Write(ex.Message);
        }
    }
}
